package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.PubBlogType;
import com.ruoyi.system.service.IPubBlogTypeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 博客分类专栏Controller
 * 
 * @author ruoyi
 * @date 2024-02-25
 */
@RestController
@RequestMapping("/system/type")
public class PubBlogTypeController extends BaseController
{
    @Autowired
    private IPubBlogTypeService pubBlogTypeService;

    /**
     * 查询博客分类专栏列表
     */
    @PreAuthorize("@ss.hasPermi('system:type:list')")
    @GetMapping("/list")
    public TableDataInfo list(PubBlogType pubBlogType)
    {
        startPage();
        List<PubBlogType> list = pubBlogTypeService.selectPubBlogTypeList(pubBlogType);
        return getDataTable(list);
    }

    /**
     * 导出博客分类专栏列表
     */
    @PreAuthorize("@ss.hasPermi('system:type:export')")
    @Log(title = "博客分类专栏", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PubBlogType pubBlogType)
    {
        List<PubBlogType> list = pubBlogTypeService.selectPubBlogTypeList(pubBlogType);
        ExcelUtil<PubBlogType> util = new ExcelUtil<PubBlogType>(PubBlogType.class);
        util.exportExcel(response, list, "博客分类专栏数据");
    }

    /**
     * 获取博客分类专栏详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:type:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(pubBlogTypeService.selectPubBlogTypeById(id));
    }

    /**
     * 新增博客分类专栏
     */
    @PreAuthorize("@ss.hasPermi('system:type:add')")
    @Log(title = "博客分类专栏", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PubBlogType pubBlogType)
    {
        return toAjax(pubBlogTypeService.insertPubBlogType(pubBlogType));
    }

    /**
     * 修改博客分类专栏
     */
    @PreAuthorize("@ss.hasPermi('system:type:edit')")
    @Log(title = "博客分类专栏", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PubBlogType pubBlogType)
    {
        return toAjax(pubBlogTypeService.updatePubBlogType(pubBlogType));
    }

    /**
     * 删除博客分类专栏
     */
    @PreAuthorize("@ss.hasPermi('system:type:remove')")
    @Log(title = "博客分类专栏", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(pubBlogTypeService.deletePubBlogTypeByIds(ids));
    }
}
